package com.fay.designPattern.pattern.create.singleton.u42;

/**
 * @Title:
 * @Description:
 * @Author Fay Wang
 * @Date 2022/4/9 9:55
 * @Version 1.0
 */
public class Singleton {
    private static Singleton instance = null;
    private final int paramA;
    private final int paramB;

    public Singleton(int paramA, int paramB) {
        this.paramA = paramA;
        this.paramB = paramB;
    }

    public synchronized static Singleton getInstance(int paramA, int paramB) {
        if (instance == null) {
            instance = new Singleton(paramA, paramB);
        } else if (instance.paramA != paramA || instance.paramB != paramB) {
            throw new RuntimeException("Singleton params is invalid, cuz Singleton has been created.");
        }
        return instance;
    }

    public static void main(String[] args) {
        Singleton instance = Singleton.getInstance(10, 50);
        System.out.println(instance);
        Singleton instance2 = Singleton.getInstance(20, 50);
    }
}
